home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / drdobbs / 1987 / 11 / main.c < prev    next >
C/C++ Source or Header  |  1987-10-08  |  3KB  |  116 lines

  1. /*----------------------------------------------------------------
  2.     main.c
  3.     Program skeleton for testing the contour map algorithm
  4.     
  5.     This program reads in a MacPaint document, unpacks
  6.     it, and calls the contour analysis algorithms.
  7.     
  8.     Once the analysis is complete the program writes out a
  9.     file called grid.dat that can be read by hidlinpix and
  10.     displayed in 3D perspective with hidden lines removed.
  11.     
  12.     hidlinpix is a program published in "Programming
  13.     Principles in Computer Graphics" by Leendert
  14.     Ammeraal (John Wiley & Sons, 1986)
  15.     
  16.     Other notes:
  17.     
  18.     Data structure libraries are derived from Alan Holub's
  19.     column in Doctor Dobb's Journal.  These include the AVL
  20.     tree and the queue.
  21.     
  22.     I modified the Lightspeed C stdio library so that the stdio
  23.     console window occupies only the lower 1/3 of the screen.
  24.     I then use the upper 2/3 for a window to display the source
  25.     contour map and a second window to display the progress of the
  26.     algorithm.
  27.     
  28.     William May
  29.     303A Ridgefield Circle
  30.     Clinton, MA 01510
  31.     
  32.     Jan 25, 1986    created
  33.   ----------------------------------------------------------------*/
  34.  
  35. #include <stdio.h>
  36. #include <WindowMgr.h>
  37. #include "contour.h"
  38.  
  39. TREE         *root = 0L;
  40. WindowPtr     left_wind;
  41. WindowPtr     right_wind;
  42. BitMap        bmap;
  43. curve_data     curves[100];        /* array of curve data */
  44.  
  45. main()
  46. {
  47.     char c;
  48.     Rect r;
  49.     int width;
  50.     
  51.     /* force the LSC stdio window to open by doing a printf */
  52.     printf("Program Starting\n\n");
  53.     
  54.     /* suppress the LSC dialog window when the program ends */
  55.     Click_On(false);
  56.  
  57.     /* open some windows... */    
  58.     init_windows();
  59.     
  60.     init_mem();
  61.  
  62.     /* read in the MacPaint document, named "test" */
  63.     if (read_MP("\ptest", &bmap)) {
  64.         r.top    = 0;
  65.         r.bottom = VBITMAX;
  66.         r.left   = 0;
  67.         r.right  = HBITMAX;
  68.         show_bmap(left_wind, &bmap, &r);
  69.                         
  70.         find_all_contours();
  71.     }
  72.  
  73.     make_hidlin();    /* make the input file for hidlinpix */
  74.  
  75.     /*
  76.        A "real" program should return allocated memory to the
  77.        system here, etc.  I will just return and let the heap
  78.        reinitialization take care of everything.
  79.     */
  80.     
  81.     printf("Program complete. <cr> to continue: ");
  82.     c = getchar();
  83. }
  84.  
  85. /*--------------------------------------------------------------------
  86.     init_windows opens the two windows used for testing graphics
  87.     algorithms.  The console window is opened automatically
  88.     by stdio when a printf is called.  No window template resources
  89.     are used.  The two window records are kept in application global
  90.     space.
  91.   --------------------------------------------------------------------*/
  92. init_windows()
  93. {
  94.     static WindowRecord left_wrec, right_wrec;
  95.     int height, width;
  96.     Rect r;
  97.     
  98.     height = 180;
  99.     width  = 144;
  100.     
  101.     r.top    = 22;
  102.     r.left   = 20;
  103.     r.bottom = r.top + height;
  104.     r.right  = r.left + width;
  105.     
  106.     left_wind = NewWindow(&left_wrec, &r, "\p", true, altDBoxProc,
  107.         FrontWindow(), false, 0L);
  108.     
  109.     r.left = 184;
  110.     r.right = r.left + width;
  111.     
  112.     right_wind = NewWindow(&right_wrec, &r, "\p", true, altDBoxProc,
  113.         FrontWindow(), false, 0L);
  114. }
  115.  
  116.